fix: Use bounded formatting for pg_stat_statements normalized placeholders#1744
Conversation
Automated security fix generated by Orbis Security AI
There was a problem hiding this comment.
Hi, @orbisai0security welcome!🎊 Thanks for taking the effort to make our project better! 🙌 Keep making such awesome contributions!
|
It will conflict with postgres/postgres@0f65f3e#diff-358df0f060121a25b138de1f148f4d3db078ba7f1aa46897f4dbbad4be724150 Also cannot understand how it could overflow here since we calculate |
|
Thanks for the detailed explanation. I agree that, given the existing sizing rule: and the invariant that each constant contributes at least one byte, while each generated placeholder is bounded to at most 11 bytes, the original overflow claim is not supported. I’ll withdraw the “critical security vulnerability” framing. The I’m happy to close this, or retitle it as a very small defensive cleanup if the project would still value replacing |
I will suggest sending a fix to the postgres community. I searched the pgsql-hackers mailing list and did not find any patches for using snprintf in pg_stats_statements. It would be really useful to discuss the issue with the postgres community as well. Also, we are based on the postgres kernel and constantly update it (since postgres is constantly developing). Therefore, the main way to fix something in the kernel code is to get a fix from postgres's code (most likely it has already been fixed), or fix something in postgres and then get a patch back. Otherwise, it is quite easy to forget to add a patch during the rebasing process. Sometimes, an issue cannot be fixed in postgres. Well, that's why our project exists. Let's do it in Cloudberry. But it seems to me that your patch is more important for postgres than for Cloudberry. Let us fix it in postgres! And sooner or later, it will be fixed in all projects based on postgres. If you suddenly have any problems with the patch review, let us know, some of the project participants are also active contributors to postgres. |
Summary
This is a defensive cleanup only.
The existing buffer sizing appears to account for the worst-case growth of replacing constants with
$nplaceholders, so this should not be treated as a demonstrated overflow or security vulnerability. The patch simply replacessprintfwithsnprintfat the placeholder formatting site to make the local write bound explicit.If this conflicts with upstream PostgreSQL pg_stat_statements normalisation work, I’m fine closing this PR in favour of that upstream change.
Changes
contrib/pg_stat_statements/pg_stat_statements.cVerification
Automated security fix by OrbisAI Security